package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"jd-mall/jd_srv/internal/svc"
	"jd-mall/jd_srv/jd_srv"
	"jd-mall/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type SetMainLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSetMainLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetMainLogic {
	return &SetMainLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SetMainLogic) SetMain(in *jd_srv.SetMainRequest) (*jd_srv.SetMainResponse, error) {
	// todo: add your logic here and delete this line
	shopImage := mysql.ShopImage{
		Model: gorm.Model{
			ID: uint(in.ImageId),
		},
		IsMain: "True",
	}
	fmt.Println(shopImage)
	err := shopImage.SetMain()
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}
	return &jd_srv.SetMainResponse{}, nil
}
